package com.ling.pl.security.model;

import com.ling.pl.core.commons.constant.TablePreDef;
import com.ling.pl.core.model.impl.BaseEntity;
import com.ling.pl.log.service.Log;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 页面菜单表
 *
 * @author bo.wang
 * @version ${ling.cloud.version}
 * @create 2016年3月15日 下午4:03:06
 */
@Entity
@Table(name = DefaultUrl.TABLE)
public class DefaultUrl extends BaseEntity {

    public static final String TABLE = TablePreDef.BASEPRE + "URL";
    public static final String SEQ = TABLE;

    @Id
    @Column(name = "URL_ID", length = 36)
    String id;

    @Column(name = "NAME", length = 60, nullable = false)
    String name;

    @Column(name = "DESCRIPTION", length = 120)
    String desc;

    @Column(name = "URL", length = 120)
    String url;

    @Column(name = "IS_FOR_NAVIGATION", nullable = false)
    boolean forNavigation = true;

    @Column(name = "SYSTEM_ID", length = 60)
    String systemId;

    @Column(name = "ICON", length = 120)
    String icon;

    @Column(name = "SORT_ORDER")
    Integer order;

    @Column(name = "target", length = 120)
    String target;

    @Column(name = "PARENT_ID", length = 60)
    String parentId;
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PARENT_ID", insertable = false, updatable = false, foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    @Cascade(CascadeType.REFRESH)
    DefaultUrl parent;

    @OneToMany(mappedBy = "parent")
    @Cascade(CascadeType.REFRESH)
    @OrderBy("order")
    List<DefaultUrl> children = new ArrayList<DefaultUrl>();

    @Transient
    boolean use;

    @Transient
    boolean hasChild;

    @Transient
    List<DefaultRole> roles;

    public DefaultUrl() {

    }

    public String getTarget() {
        return target;
    }

    public void setTarget(String target) {
        this.target = target;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public Integer getOrder() {
        return order;
    }

    public void setOrder(Integer order) {
        this.order = order;
    }

    public boolean isUse() {
        return use;
    }

    public void setUse(boolean use) {
        this.use = use;
    }

    public List<DefaultUrl> getChildren() {
        return children;
    }

    public void setChildren(List<DefaultUrl> children) {
        this.children = children;
    }

    public boolean isForNavigation() {
        return forNavigation;
    }

    public void setForNavigation(boolean forNavigation) {
        this.forNavigation = forNavigation;
    }

    public List<DefaultRole> getRoles() {
        return roles;
    }

    public void setRoles(List<DefaultRole> roles) {
        this.roles = roles;
    }

    public String getSystemId() {
        return systemId;
    }

    public void setSystemId(String systemId) {
        this.systemId = systemId;
    }

    public String toString() {
        return name;
    }

    public DefaultUrl getParent() {
        return parent;
    }

    public void setParent(DefaultUrl parent) {
        this.parent = parent;
    }

    public boolean isHasChild() {
        return hasChild;
    }

    public void setHasChild(boolean hasChild) {
        this.hasChild = hasChild;
    }

    public Serializable getBusinessId() {
        return getId();
    }

    public String toLogString(String operationType, Log log) {
        return " 名称:" + getName() + " 描述:" + getDesc() + " 地址:" + getUrl() + " 排序:" + getOrder() + " 目标:" + getTarget();
    }

}
